package com.example.scholarship.controller;

import com.example.scholarship.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import lombok.Getter;
import lombok.Setter;
@CrossOrigin
@RestController
public class usercontroller
{
    @Autowired
    UserMapper UserMapper;
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

    @PostMapping("/api/login")
    public LoginResponse login(@RequestBody LoginRequest loginRequest) {
        // 这里仅做示例，实际应用中应该从数据库中查询用户信息
        String expectedPassword = passwordEncoder.encode("admin"); // 假设的已加密密码
        if ("admin".equals(loginRequest.getUsername()) && passwordEncoder.matches(loginRequest.getPassword(), expectedPassword)) {
            return new LoginResponse(true, "登录成功，欢迎回来，admin！");
        } else {
            return new LoginResponse(false, "用户名或密码错误！");
        }
    }
}
@Getter
@Setter
class LoginRequest {
    private String username;
    private String password;

    // getters and setters
}
class LoginResponse {
    private boolean success;
    private String message;

    public LoginResponse(boolean success, String message) {
        this.success = success;
        this.message = message;
    }

    // getters and setters
}
